/*
 * adc.c
 *
 * Created:			05.08.2012 21:07:03
 * Author:			boecki91@gmail.com
 * Target:			atMEGA644P
 * URL:				$HeadURL: http://dc-motor-regelung.googlecode.com/svn/trunk/Software/adc.c $
 * Last changed by:	$Author: boecki91@gmail.com $
 * Changed date:    $Date: 2012-08-05 20:21:36 +0000 (Sun, 05 Aug 2012) $
 * Last committed:  $Revision: 12 $
 *
 * ID:				$Id: adc.c 12 2012-08-05 20:21:36Z boecki91@gmail.com $
*/
#include "global.h"
#include <avr/io.h>

void adc_init(void)
{
	//ADC
	ADCSRA = (1<<ADEN);
	
	//Dummy ADC
	ADCSRA |= (1<<ADSC);
	while (ADCSRA & (1<<ADSC) )
	{
		
	}
	ADCW = ADCW;
}
uint16_t adc_read(uint8_t channel)
{
	ADMUX = (ADMUX & ~(0x1F)) | (channel & 0x1F);
	ADCSRA |= (1<<ADSC);
	while (ADCSRA & (1<<ADSC) ) {}
}